package com.ssyt.hiring.web.dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.ssyt.cdp.common.BaseDao;
import com.ssyt.cdp.common.PageModel;
import com.ssyt.cdp.common.util.StringUtil;
import com.ssyt.hiring.entity.PositionEntity;

@Repository
public class PositionDao extends BaseDao<PositionEntity, Integer> {

	public PageModel<PositionEntity> listAll(String queryStr, int pageNo,
			int pageSize) {
		List<Object> paramList = new ArrayList<>();
		StringBuffer hql = new StringBuffer();
		hql.append("SELECT new PositionEntity(p.name, p.salary1, p.salary2, p.releaseTime, c.name AS companyName, c.slogan AS companySlogan, c.address AS companyAddress) ");
		hql.append("FROM PositionEntity p, CompanyEntity c ");
		hql.append("WHERE p.companyId=c.id ");
		if (StringUtil.isNotBlank(queryStr)) {
			hql.append("AND p.name LIKE ? OR c.name LIKE ? ");
			paramList.add("%" + queryStr + "%");
			paramList.add("%" + queryStr + "%");
		}
		hql.append("ORDER BY p.id DESC ");
		return pageEntityByHql(pageNo, pageSize, hql.toString(), paramList);
	}
}
